//---------------------------------------------------------------------
// Author: Keith Hill, jachymko
//
// Description: Installer class creating the $Env:PscxHome variable.
//
// Creation Date: Dec 19, 2006
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

namespace Pscx.Install
{
    [RunInstaller(true)]
    public class EnvironmentInstaller : PscxInstallerBase
    {
        const string PscxHomeEnvVar = "PscxHome";

        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);

            if (InstallDir != null)
            {
                SetVariable(InstallDir);
            }
        }

        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);

            SetVariable(null);
        }

        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);

            SetVariable(null);
        }

        void SetVariable(string value)
        {
            Environment.SetEnvironmentVariable(PscxHomeEnvVar, value, EnvironmentVariableTarget.Machine);
        }
    }
}
